package com.buba.service.impl;
import com.buba.mapper.DepartmentManagementMapper;
import entity.sparemanage.vo.PeopleVo;
import entity.system.DepartmentManagement;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import entity.system.PeopleManagement;
import com.buba.mapper.PeopleManagementMapper;
import com.buba.service.PeopleManagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 人员管理 服务实现类
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@Service
public class PeopleManagementServiceImpl extends ServiceImpl<PeopleManagementMapper, PeopleManagement> implements PeopleManagementService {

    @Autowired
    private PeopleManagementMapper peopleManagementMapper;

    @Autowired
    private DepartmentManagementMapper departmentManagementMapper;
    /* *
     * @Author: beisheng
     * @Descriprion: 根据人员ID查询人员信息和部门
     * @Date: 2023/5/25 9:55
     * @Return: entity.sparemanage.vo.PeopleVo
     * @Param: [id]
     */

    @Override
    public PeopleVo selOnePeople(Integer id) {
        PeopleVo peopleVo = new PeopleVo();
        PeopleManagement peopleManagement = peopleManagementMapper.selectById(id);
        BeanUtils.copyProperties(peopleManagement,peopleVo);
        DepartmentManagement departmentManagement = departmentManagementMapper.selectById(peopleManagement.getPeopleManagementDepartmentId());
        peopleVo.setDepartmentName(departmentManagement.getDepartmentName());
        return peopleVo;
    }
    /**
     * @return common.R
     * @Author atlong
     * @Description 查询人员信息
     * @Date 2023/6/14 11:00
     * @Param []
     **/
    @Override
    public List<PeopleManagement> selPrincipals() {
        QueryWrapper<PeopleManagement> wrapper = new QueryWrapper<>();
        wrapper.eq("delete_flag",0);
        wrapper.eq("people_management_state",1);
        List<PeopleManagement> list = peopleManagementMapper.selectList(wrapper);
        return list;
    }
}
